package giectech.spring.data.serviceImpl;

import giectech.spring.data.mapper.CoffeeMapper;
import giectech.spring.data.model.Coffee;
import giectech.spring.data.service.CoffeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.transaction.RollbackException;
import java.util.List;

/**
 * @author Administrator
 * @title: CoffeeServiceImpl
 * @projectName springnewbucks
 * @description: TODO
 * @date 2022/8/1915:53
 */
@Component
public class CoffeeServiceImpl implements CoffeeService {

    @Autowired
    private CoffeeMapper coffeeMapper;

    @Override
    @Transactional
    public List<Coffee> findOneCoffeeByName(String name) {
        return coffeeMapper.findOneCoffeeByName(name);
    }

    @Override
    public Coffee findOneCoffeeById(long id) {
        return coffeeMapper.findOneCoffeeById(id);
    }

    @Override
    @Transactional(rollbackFor = RollbackException.class)
    public int save(Coffee coffee) {
        return coffeeMapper.insert(coffee);
    }

    @Override
    @Transactional(rollbackFor = RollbackException.class)
    public int updateByPrimaryKey(Coffee record) {
        return coffeeMapper.updateByPrimaryKey(record);
    }

    @Override
    @Transactional(rollbackFor = RollbackException.class)
    public int deleteByPrimaryKey(Long id) {
        return coffeeMapper.deleteByPrimaryKey(id);
    }
}
